package com.yishan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yishan.dao.DrawDao;
import com.yishan.domain.Draw;
import com.yishan.service.DrawService;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author yishan
 * @Date 2021/4/28 0028 16:18
 * @Version 1.0
 */
@Service
public class DrawSereviceImpl implements DrawService {

	@Autowired
	private DrawDao drawDao;

	@Override
	public void save(Draw draw) {

		// id使用UUID的生成策略来获取
		String id = UUID.randomUUID().toString().replace("-","").substring(0,15);
		draw.setId(id);
		drawDao.save(draw);

	}

	@Override
	public void delete(String id) {
		drawDao.delete(id);
	}


	@Override
	public void deleteMany(String ids) {
		String[] idss = ids.split(",");
		for (String s : idss) {
			delete(s);
		}
	}

	@Override
	public void update(Draw draw) {

		drawDao.update(draw);

	}

	@Override
	public Draw findById(String id) {

		return drawDao.findById(id);

	}

	@Override
	public List<Draw> findAll() {

		return drawDao.findAll();

	}

	@Override
	public PageInfo findAll(int page, int size) {

		PageHelper.startPage(page,size);
		List<Draw> list = drawDao.findAll();
		return new PageInfo(list);

	}

	@Override
	public PageInfo findTypeId(int page, int size, String id) {
		PageHelper.startPage(page,size);
		List<Draw> list = drawDao.findTypeId(id);
		return new PageInfo(list);
	}

}
